package com.sinoglobal.dumping.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.lidroid.xutils.BitmapUtils;
import com.sinoglobal.dumping.R;
import com.sinoglobal.dumping.bean.Dumpling_AdvertisingBean;
import com.sinoglobal.dumping.bean.Dumpling_AdvertisingResultList;

import java.util.List;

/**
 * Created by KeZhuang on 2016/1/8.
 */
public class Dumpling_HomeAdapter extends BaseAdapter{
    private List<Dumpling_AdvertisingResultList> listData;
    private Context mContext;
    private BitmapUtils bitmapUtils;
    public Dumpling_HomeAdapter(Context context){
        mContext = context;
        bitmapUtils = new BitmapUtils(mContext);
        bitmapUtils.configDefaultLoadingImage(R.drawable.dumpling_img_default);
        bitmapUtils.configDefaultLoadFailedImage(R.drawable.dumpling_img_default);
    }
    @Override
    public int getCount() {
        return listData!=null?listData.size():0;
    }

    public void setData(List<Dumpling_AdvertisingResultList> list){
        listData = list;
        notifyDataSetChanged();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public boolean isEnabled(int position) {
        return false;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoder viewHoder;
        if(convertView==null){
            viewHoder = new ViewHoder();
            convertView = View.inflate(mContext, R.layout.dumpling_home_item,null);
            viewHoder.imageview = (ImageView) convertView;
            int width = mContext.getResources().getDimensionPixelOffset(R.dimen.px150);
            int height = mContext.getResources().getDimensionPixelOffset(R.dimen.px100);
            viewHoder.imageview.setLayoutParams(new AbsListView.LayoutParams(width,height));
            convertView.setTag(viewHoder);
        }else{
            viewHoder = (ViewHoder) convertView.getTag();
        }
        bitmapUtils.display(viewHoder.imageview,listData.get(position).getAdvpic());
        return convertView;
    }
    class ViewHoder{
        ImageView imageview;
    }
}
